/**
 * 封装cookie作为缓存
 * @param key
 * @returns {{getCache(): CookieRef<string | null | undefined>, setCache(*): void, remove(): void}|CookieRef<string | null | undefined>}
 */
export const useCache = (key) => {
  // 缓存前缀
  const BASEKEY = "KONG:NUXT:"
  // 把key拼接存入cookie中
  const cookie = useCookie(BASEKEY + key);
  // 返回
  return {
    // 设置缓存
    setCache(value){
      cookie.value = value
    },
    // 获取缓存
    getCache(){
      return cookie
    },
    // 删除缓存
    remove(){
      cookie.value = null
    }
  }
}
